home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / Virtual User 1.0 / Example Scripts / SelfTour.vu < prev    next >
Text File  |  1991-01-25  |  16KB  |  564 lines

  1. #
  2. #    File:        SelfTour.vu
  3. #
  4. #    Contains:    A VU self-tour script to be run against MacPaint 2.0
  5. #
  6. #                Before running this script, MacPaint must be launched.
  7. #                This script creates two documents called 'VU Speaks' and 'Diagram' which
  8. #                are deleted at the end of the script.
  9. #
  10. #    Conventions:    Global variables begin with a capital letter
  11. #
  12. #    Written by:    Jay Jessen
  13. #
  14. #    Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  15. #
  16. #    Change History:
  17. #
  18. #        5/17/90        JAS        Create globals Number_of_moves and Max_mouse_speed.  A few small
  19. #                            changes in comment header.
  20. #        
  21. #        11/7/89           Jay        creation    
  22. #
  23. #    To Do:
  24. #
  25.  
  26. # ********************************************************************************************
  27. # Select a tool from the "Tools" pallette
  28. task select_tool_from_menubar(paint_tool) begin
  29.     old_speed := mouseSpeed(2);
  30.     move a : { 360,10 };
  31.     wait(1);
  32.     pressMouse;
  33.     move absolute: { ((paint_tool[2]) * 23) + 341,((paint_tool[1]) * 20) + 58 };
  34.     wait(1);
  35.     releaseMouse;
  36.     global Current_tool := paint_tool;
  37.     mouseSpeed(old_speed);
  38. end;
  39.  
  40.  
  41. # ********************************************************************************************
  42. # Tear off the "Tools" pallette
  43. task tear_off_tool_pallette() begin
  44.     old_speed := mouseSpeed(2);
  45.     move absolute: { 360,10 };
  46.     wait(1);
  47.     pressMouse;
  48.     wait(1);
  49.     for i := 1 to 200 step 50 move relative: { 0,50 };
  50.     releaseMouse;
  51.     mouseSpeed(old_speed);
  52. end;
  53.  
  54.  
  55. # ********************************************************************************************
  56. task close_tool_pallette() begin
  57.     if match[window t:'Tool' r:?pal_rect]! begin
  58.         old_speed := mouseSpeed(2);
  59.         move absolute: { pal_rect[1] + 11,pal_rect[2] + 5 };
  60.         wait(1);
  61.         click;
  62.         mouseSpeed(old_speed);
  63.     end;
  64. end;
  65.  
  66.  
  67. # ********************************************************************************************
  68. # Tear off the Tools pallette (if not already torn off) and position it against the Diag window. 
  69. task position_tear_off_tool_pallette() begin
  70.  
  71.     global Diagram_wind_title;
  72.     
  73.     if(not match[window t:'Tool']!)
  74.         tear_off_tool_pallette();
  75.     winder := match[window t:/?{Diagram_wind_title}≈/]!;
  76.     match [window t:'Tool' r:?tool_rect]!;
  77.     drag [window t:'Tool']! 
  78.             absolute: {    winder.rect[3] - (tool_rect[3] - tool_rect[1]),
  79.                         winder.rect[4] - (tool_rect[4] - tool_rect[2]) };
  80. end;
  81.  
  82.  
  83. # ********************************************************************************************
  84. task position_cursor_over_floating_tool(paint_tool) begin
  85.     if(not match[window t:'Tool']!)
  86.         position_tear_off_tool_pallette();
  87.     match [window t:'Tool' r:?tool_rect]!;
  88.     old_speed := mousespeed(2);
  89.     move absolute: {    (tool_rect[1] + 12) + (paint_tool[2] * 23),
  90.                         (tool_rect[2] + 48) + (paint_tool[1] * 20)};
  91.     mousespeed(old_speed);
  92. end;
  93.  
  94.  
  95. # ********************************************************************************************
  96. task select_tool_from_floating_tool_pallette(paint_tool) begin
  97.     position_cursor_over_floating_tool(paint_tool);
  98.     click;
  99.     global current_tool := paint_tool;
  100. end;
  101.  
  102.  
  103. # ********************************************************************************************
  104. task select_tool(paint_tool) begin
  105.     if(match[window t:'Tool']!) select_tool_from_floating_tool_pallette(paint_tool);
  106.     else select_tool_from_menubar(paint_tool);
  107. end;
  108.  
  109.  
  110. # ********************************************************************************************
  111. task double_click_tool_from_floating_tool_pallette(paint_tool) begin
  112.     position_cursor_over_floating_tool(paint_tool);
  113.     doubleClick;
  114. end;
  115.  
  116.  
  117. # ********************************************************************************************
  118. task select_pattern_from_menubar(pattern_column,pattern_row) begin
  119.     old_speed := mouseSpeed(2);
  120.     move a : { 260,19 };
  121.     wait(1);
  122.     pressMouse;
  123.     move relative: { (pattern_column * 20) + 10,(pattern_row * 17) + 8 };
  124.     wait(1);
  125.     releaseMouse;
  126.     mouseSpeed(old_speed);
  127. end;
  128.  
  129.  
  130. # ********************************************************************************************
  131. task select_file(path,depth := 32) begin
  132.     pressKey keystrokes: { commandKey };
  133.     for i := 1 to depth begin
  134.         type keystrokes: { uparrowKey };
  135.     end;
  136.     releaseKey keystrokes: { commandKey };
  137.     for each path_element in path begin
  138.         type keystrokes: { path_element,returnKey };
  139.     end;
  140. end;
  141.  
  142.  
  143. # ********************************************************************************************
  144. task open_file(path,depth := 32) begin
  145.     select [menuItem t:/Open≈/ m:'File'];
  146.     select_file(path,depth);
  147. end;
  148.  
  149.  
  150. # ********************************************************************************************
  151. task draw_mac_icon(x,y) begin
  152.  
  153.     global pencil;
  154.     global frame_rect;
  155.     global shade_rect;
  156.     
  157.     # compute the body frame
  158.     mac_frame := { x,y,x + 50,y + 51 };
  159.     
  160.     # draw the body frame
  161.     select_tool(frame_rect);
  162.     old_speed := mouseSpeed(2);
  163.     move absolute: { mac_frame[1],mac_frame[2] };
  164.     pressMouse;
  165.     move relative: { 50,51 };
  166.     wait(1);
  167.     releaseMouse;
  168.     
  169.     # draw the base
  170.     move absolute: { mac_frame[1] + 2,mac_frame[4] };
  171.     pressMouse;
  172.     move relative: { 46,11 };
  173.     wait(1);
  174.     releaseMouse;
  175.     
  176.     # draw the screen
  177.     move absolute: { mac_frame[1] + 6,mac_frame[2] + 6 };
  178.     pressMouse;
  179.     move relative: { 38,3 };
  180.     wait(1);
  181.     releaseMouse;
  182.     
  183.     select_pattern_from_menubar(3,0); # select the ltGray pattern (standard desktop pattern)
  184.     select_tool(shade_rect);
  185.     move absolute: { mac_frame[1] + 6,mac_frame[2] + 9 };
  186.     wait(1);
  187.     pressMouse;
  188.     move relative: { 38,24 };
  189.     wait(1);
  190.     releaseMouse;
  191.     select_tool(pencil);
  192.     move absolute: { mac_frame[3] - 7,mac_frame[4] - 11 };
  193.     wait(1);
  194.     pressMouse;
  195.     move relative: { -15,0 };
  196.     wait(1);
  197.     releaseMouse;
  198.     mouseSpeed(old_speed);
  199. end;
  200.  
  201.  
  202. # ********************************************************************************************
  203. task touch_up_mac_icon(x,y) begin
  204.  
  205.     global pencil,current_tool;
  206.     
  207.     activate_diagram_window();
  208.     if((current_tool[1] <> pencil[1]) or (current_tool[2] <> pencil[2])) begin
  209.         select_tool(pencil);
  210.     end;
  211.     old_speed := mouseSpeed(2);
  212.     move absolute: { x,y };
  213.     click; wait(1);
  214.     move relative: { 50,0 };
  215.     click; wait(1);
  216.     move relative: { 0,51 };
  217.     click; wait(1);
  218.     move relative: { -50,0 };
  219.     click; wait(1);
  220.     move relative: { 2,11 };
  221.     click; wait(1);
  222.     move relative: { 46,0 };
  223.     click; wait(1);
  224.     move relative: { -42,-56 };
  225.     click; wait(1);
  226.     move relative: { 38,0 };    
  227.     click; wait(1);
  228.     move relative: { 0,27 };    
  229.     click; wait(1);
  230.     move relative: { -38,0 };    
  231.     click; wait(1);
  232.     mouseSpeed(old_speed);
  233. end;
  234.  
  235.  
  236. # ********************************************************************************************
  237. task select_mac_icon(x,y) begin
  238.     
  239.     global marquee;
  240.     
  241.     activate_diagram_window();
  242.     select_tool(marquee);
  243.     old_speed := mouseSpeed(2);
  244.     move absolute:{ x,y };
  245.     wait(1);
  246.     pressMouse;
  247.     move relative: { 50,62 };
  248.     wait(1);
  249.     releaseMouse;
  250.     mouseSpeed(old_speed);
  251. end;
  252.  
  253.  
  254. # ********************************************************************************************
  255. task move_mac_icon(at,move_to) begin
  256.     activate_diagram_window();
  257.     select_mac_icon(at[1],at[2]);
  258.     old_speed := mouseSpeed(2);
  259.     move absolute: { at[1],at[2] };
  260.     wait(1);
  261.     pressMouse;
  262.     move absolute: { move_to[1],move_to[2] };
  263.     wait(1);
  264.     releaseMouse;
  265.     mouseSpeed(old_speed);
  266. end;
  267.  
  268.  
  269. # ********************************************************************************************
  270. task copy_mac_icon(at,move_to) begin
  271.     activate_diagram_window();
  272.     select_mac_icon(at[1],at[2]);
  273.     old_speed := mouseSpeed(2);
  274.     move absolute: { at[1],at[2] };
  275.     wait(1);
  276.     pressKey keystrokes: { optionKey };
  277.     pressMouse;
  278.     move absolute: { move_to[1],move_to[2] };
  279.     wait(1);
  280.     releaseMouse;
  281.     mouseSpeed(old_speed);
  282.     releaseKey keystrokes: { optionKey };
  283. end;
  284.  
  285.  
  286. # ********************************************************************************************
  287. task center_text() begin
  288.     match [menuItem m:'Style' t:'Align Middle' c:?checked]!;
  289.     if(checked = '') begin
  290.         select [menuItem m:'Style' t:'Align Middle']!;
  291.     end;
  292. end;
  293.  
  294.  
  295. # ********************************************************************************************
  296. task type_text(message_text) begin
  297.  
  298.     global text_tool,Text_wind_title,current_tool;
  299.     
  300.     winder := match[window t:/?{Text_wind_title}≈/]!;
  301.     activate_text_window();
  302.     text_length := card(message_text);
  303.     if((current_tool[1] <> text_tool[1]) or (current_tool[2] <> text_tool[2])) begin
  304.         select_tool(text_tool);
  305.     end;
  306.     center_click_x := (winder.rectangle[3] - winder.rectangle[1] - 16) / 2;
  307.     
  308.     center_click_y := ((winder.rectangle[4] - winder.rectangle[2] - 34) / 2) + 18 + winder.rectangle[2];
  309.     old_speed := mouseSpeed(2);
  310.     move absolute: { center_click_x,center_click_y };
  311.     click;
  312.     mouseSpeed(old_speed);
  313.     type keystrokes: { message_text };
  314. end;
  315.  
  316.  
  317. # ********************************************************************************************
  318. task select_font_and_style(font_selection := 'Geneval',style_selection := '9 point') begin
  319.     select [menuItem t:font_selection m:'Font']!;
  320.     select [menuItem t:style_selection m:'Style']!;
  321. end;
  322.  
  323.  
  324. # ********************************************************************************************
  325. task activate_diagram_window() begin
  326.     
  327.     global Diagram_wind_title; # window number 1
  328.     global Text_wind_title; # window number 2
  329.     
  330.     if match[window t:'Tool']! begin
  331.         front := 2; back := 3;
  332.     end;
  333.     else begin
  334.         front := 1; back := 2;
  335.     end;
  336.     match[window o:front rect:?front_rect]!;
  337.     match[window o:back rect:?back_rect]!;
  338.     if (front_rect[2] > back_rect[2]) begin
  339.         select [window o:back]!;
  340.     end;
  341. end;
  342.  
  343.  
  344. # ********************************************************************************************
  345. task activate_text_window() begin
  346.     
  347.     global Diagram_wind_title; # window number 1
  348.     global Text_wind_title; # window number 2
  349.     
  350.     if match[window t:'Tool']! begin
  351.         front := 2; back := 3;
  352.     end;
  353.     else begin
  354.         front := 1; back := 2;
  355.     end;
  356.     match[window o:front rect:?front_rect]!;
  357.     match[window o:back rect:?back_rect]!;
  358.     if (front_rect[2] < back_rect[2]) begin
  359.         select [window o:back]!;
  360.     end;
  361. end;
  362.  
  363.  
  364. # ********************************************************************************************
  365. task save_as(window_number,replace_existing_selection := 'No') begin
  366.  
  367.     global Diagram_wind_title; # window number 1
  368.     global Text_wind_title; # window number 2
  369.     
  370.     if (window_number = 1) begin
  371.         current_title := Diagram_wind_title;
  372.         activate_diagram_window();
  373.     end;
  374.     else begin
  375.         current_title := Text_wind_title;
  376.         activate_text_window();
  377.     end;
  378.     select [menuItem t:/Save As≈/ m:'File'];
  379.     count := 0;
  380.     made_unique := false;
  381.     while match [window ord:1 style:dialog]! begin
  382.         match[editText t:?editable_text w:[window ord:1 style:dialog]]!;
  383.         if editable_text begin
  384.             for i := 1 to card(editable_text) type keystrokes: { backspaceKey };
  385.         end;
  386.         type keystrokes: { current_title };
  387.         if(count) type keystrokes: { "-",count };
  388.         select [button t:'Save' wind:[window ord:1]]!;
  389.         if(    match[button t:'Yes' w:[window ord:1 style:dialog]] and
  390.                 match[button t:'No' w:[window ord:1 style:dialog]] and
  391.                 match[staticText t:/Replace existing≈/ w:[window ord:1 style:dialog]] ) begin
  392.             select [button t:replace_existing_selection w:[window ord:1 s:dialog]]!;
  393.         end;
  394.         if (window_number = 1) begin
  395.             match[editText t:?Diagram_wind_title w:[window ord:1 style:dialog]];
  396.             current_title := Diagram_wind_title;
  397.         end;
  398.         else begin
  399.             match[editText t:?Text_wind_title w:[window ord:1 style:dialog]];
  400.             current_title := Text_wind_title;
  401.         end;
  402.         count := count + 1;
  403.     end;
  404. end;
  405.  
  406.  
  407. # ********************************************************************************************
  408. task tile_and_title_windows(picture_percentage := 75) begin
  409.     window_count := card(collect[window]);
  410.     if window_count > 2 begin
  411.         for i := 1 to window_count - 2 begin
  412.             close [window];
  413.         end;
  414.     end;
  415.     else begin
  416.         if window_count begin
  417.             if window_count = 1 begin
  418.                 select [menuItem t:/New≈/ m:'File'];
  419.             end;
  420.         end;
  421.         else begin
  422.             select [menuItem t:/New≈/ m:'File'];
  423.             select [menuItem t:/New≈/ m:'File'];
  424.         end;
  425.     end;
  426.     picture_height := (338 * picture_percentage) / 100;
  427.     drag [window] absolute: { 0,20 };
  428.     size [window] height:picture_height w:512;
  429.     select [window ord:2];
  430.     size [window] height:338 - picture_height  w:512;
  431.     drag [window] absolute: { 0,picture_height + 4 };
  432. end;
  433.  
  434.  
  435. # ********************************************************************************************
  436. task erase_text_window() begin
  437.  
  438.     global eraser;
  439.     
  440.     activate_text_window();
  441.     double_click_tool_from_floating_tool_pallette(eraser);
  442. end;
  443.  
  444.  
  445. # ********************************************************************************************
  446. task pause_then_erase_text(duration) begin
  447.     wait(duration);
  448.     erase_text_window();
  449. end;
  450.  
  451.  
  452. # ********************************************************************************************
  453. task close_all_windows_without_saving() begin
  454.     close_tool_pallette();
  455.     while match[window] begin
  456.         close [window];
  457.         if match[window s:dialog k:{[button t:'Yes'],[button t:'Cancel'],[button t:'No']}]! begin
  458.             select [button t:'No' w:[window o:1]]!;
  459.         end;
  460.     end;
  461. end;
  462.  
  463.  
  464. # ********************************************************************************************
  465. task label_mac_icon(x,y,label) begin
  466.  
  467.     global text_tool,current_tool;
  468.     
  469.     activate_diagram_window();
  470.     if((current_tool[1] <> text_tool[1]) or (current_tool[2] <> text_tool[2])) begin
  471.         select_tool(text_tool);
  472.     end;
  473.     old_speed := mouseSpeed(2);
  474.     move absolute: { x + 25,y + 79 };
  475.     click;
  476.     mouseSpeed(old_speed);
  477.     type keystrokes:{ label };
  478. end;
  479.  
  480.  
  481. #####   EXECUTION STARTS HERE  ######
  482.  
  483. # the following is a list of parameters that can be passed to select_tool()
  484. marquee             := { 0,0 };
  485. lasso                 := { 0,1 };
  486. frame_rect             := { 0,2 };
  487. shade_rect             := { 0,3 };
  488. hand                 := { 1,0 };
  489. line                 := { 1,1 };
  490. frame_round_rect     := { 1,2 };
  491. shade_round_rect     := { 1,3 };
  492. pail                 := { 2,0 };
  493. spray_can             := { 2,1 };
  494. frame_oval             := { 2,2 };
  495. shade_oval             := { 2,3 };
  496. brush                 := { 3,0 };
  497. pencil                 := { 3,1 };
  498. frame_region         := { 3,2 };
  499. shade_region         := { 3,3 };
  500. text_tool             := { 4,0 };
  501. eraser                 := { 4,1 };
  502. frame_polygon         := { 4,2 };
  503. shade_polygon         := { 4,3 };
  504.  
  505. patience(2);
  506. Pause_between_frames := 1;
  507.  
  508. Diagram_wind_title    := 'Diagram';
  509. Text_wind_title     := 'VU Speaks';
  510.  
  511. close_all_windows_without_saving();
  512. tile_and_title_windows(50);
  513. save_as(1,'Yes');
  514. save_as(2,'Yes');
  515.  
  516. select_tool(text_tool);
  517. current_tool := text_tool;
  518. center_text();
  519.  
  520. # Set font and size
  521. if (not ((match[menuItem t:'Chicago' m:'Font']).checked))
  522.     select [menuItem t:'Chicago' m:'Font'];
  523. if (not ((match[menuItem t:'12' m:'Style']).checked))
  524.     select [menuItem t:'12' m:'Style'];
  525.  
  526. # Type some introductory text
  527. type_text("Hello, I am your Virtual User∂nHelping you test software at the human interface level is my life");
  528. pause_then_erase_text(Pause_between_frames);
  529. type_text("I run over Appletalk so I need at least 2 machines");
  530. pause_then_erase_text(Pause_between_frames);
  531. type_text("One to run the VU software∂n--for now this is the VU Tool within MPW");
  532.  
  533. # Draw, label, and touch up Mac icon
  534. activate_diagram_window();
  535. match [window t:/?{Diagram_wind_title}≈/ r:?rect]!;
  536. rect := { rect[1] + 50,rect[2] + 38 };
  537. draw_mac_icon(rect[1],rect[2]);
  538. label_mac_icon(rect[1],rect[2],'VU Machine');
  539. pause_then_erase_text(Pause_between_frames);
  540. type_text("I should really touch up those corners∂nBut who needs fatbits, my eye/hand coordination is great!");
  541. touch_up_mac_icon(rect[1],rect[2]);
  542.  
  543. # Create target Mac by copying and pasting VU Machine
  544. pause_then_erase_text(Pause_between_frames);
  545. type_text("Another machine is needed to run the test against∂n--it requires the Agent VU to be installed");
  546. copy_mac_icon( { rect[1],rect[2] }, { rect[1] + 150,rect[2] } );
  547. label_mac_icon(rect[1] + 150,rect[2],'Target Machine');
  548.  
  549. # Show a few simple commands
  550. pause_then_erase_text(Pause_between_frames);
  551. close_tool_pallette();
  552. type_text(
  553.     "I can do simple things like menu selections∂nFor example, I will execute the following commands for you:∂nselect [menuItem t:'Monaco' m:'Font'];∂nselect [menuItem t:'9 point' m:'Style'];");
  554. select [menuItem t:'Monaco' m:'Font'];
  555. select [menuItem t:'9 point' m:'Style'];
  556.  
  557. # Quit the program
  558. select[menuitem t:'Quit' m:'File'];
  559. wait(1);
  560. if match[button t:'No' w:1] select [button t:'No' w:1];
  561. wait(1);
  562. if match[button t:'No' w:1] select [button t:'No' w:1];
  563. wait(1);
  564.